package com.yidu.best.basicSetup.trusteeset.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.best.basicSetup.fundset.domain.Fund;
import com.yidu.best.basicSetup.trusteeset.domain.Trustee;
import com.yidu.best.basicSetup.trusteeset.domain.TrusteeVo;
import com.yidu.best.basicSetup.trusteeset.service.TrusteeService;

@Controller
@RequestMapping("/TrusteeController/")
public class TrusteeController {
	
	@Autowired
	private TrusteeService trusteeService;

	public TrusteeService getTrusteeService() {
		return trusteeService;
	}

	public void setTrusteeService(TrusteeService trusteeService) {
		this.trusteeService = trusteeService;
	}

	public TrusteeController(TrusteeService trusteeService) {
		super();
		this.trusteeService = trusteeService;
	}

	public TrusteeController() {
		
	}
	
	
	/**
	 * 跳转页面
	 * @return
	 */
	@RequestMapping(value="trusteeList", method= RequestMethod.GET)
	public String getFundManager() {
		System.out.println("trusteeList");
		return "sys/Trustee/TrusteeList";
	}
	
	
	/**
	 * 查询所有分页查询
	 * @param trusteeVo
	 * @return
	 */
	@RequestMapping(value = "queryTrustee", method= RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> queryTrusteePage(TrusteeVo trusteeVo){
		
		Map<String,Object> trusteeMap = trusteeService.findQueryPageTrustee(trusteeVo);
		
		return trusteeMap;
		
	}
	
	/**
	 * 添加
	 * @param trustee
	 * @return
	 */
	@RequestMapping(value = "trustee",method = RequestMethod.POST)
	@ResponseBody
	public boolean addFund(Trustee trustee) {
		System.out.println("abc"+trustee);
		int rs = trusteeService.addTrustee(trustee);
		if(rs==1) {
			return true;
		}
		
		return false;
	}
	
	
	/**
	 * 修改方法
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "updatetrustee",method = RequestMethod.PUT)
	public boolean updateExchange(Trustee trustee) {
		System.out.println(trustee);
		//调用业务层修改方法
		int rs = trusteeService.updateTrustee(trustee);
		//如何rs=1 则修改成功
		if(rs==1) {
			//跳到list页面
			return true;
		}else {
			return false;
		}
		
	}
	
	/**
	 * 删除
	 * @param area
	 * @return 
	 */
	@ResponseBody
	@RequestMapping(value = "trustee/{trusteeIds}", method = RequestMethod.DELETE)
	public boolean deleteTrustee(@PathVariable("trusteeIds")String trusteeIds ) {
		//定义变量
		int rs=0;
		//定义数组接受前台返回的字符串数组 将,去掉
        String[] trusteeId = trusteeIds.split(",");
        //将接收的数组遍历
        for (int i = 0; i < trusteeId.length; i++) {
        	//调用业务层方法
        	rs = trusteeService.deleteTrustee(trusteeId[i]);
        }
        if(rs==1) {
        	return true;
        }
        return false;
	}
	

	
	
	
	
	
	
}
